//
//  WSJIdViewController.m
//  RunningMan
//
//  Created by Run on 16/5/25.
//  Copyright © 2016年 WSJ. All rights reserved.
//

#import "WSJIdViewController.h"
#import "WSJPickerView.h"
#import "TableViewCell.h"
@interface WSJIdViewController ()<UITableViewDataSource,UITableViewDelegate,WSJPickerViewDelegate>
{
    
    NSInteger selectIndex;
    
}
@property (strong, nonatomic)UITableView *selectTv;
@property (strong, nonatomic)NSMutableArray *selectArray;
@property (strong, nonatomic)UIButton *returnBtn;

@end

@implementation WSJIdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.returnBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.returnBtn.frame = CGRectMake(15, 24, 50, 40);
    [self.view addSubview:self.returnBtn];
    [self.returnBtn setTitleColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1] forState:UIControlStateNormal];
    [self.returnBtn setTitle:@"返回" forState:UIControlStateNormal];
    [self.returnBtn addTarget:self action:@selector(returnB) forControlEvents:UIControlEventTouchUpInside];
    self.selectArray = [NSMutableArray array];
    UINib *nib = [UINib nibWithNibName:@"TableViewCell" bundle:nil];
    [self.selectTv registerNib:nib forCellReuseIdentifier:@"select"];
    NSString *plistPath = [[NSBundle mainBundle]pathForResource:@"Property List" ofType:@"plist"];
    NSArray *arr = [[NSArray alloc]initWithContentsOfFile:plistPath];
    for (NSDictionary *dict in arr) {
        [self.selectArray addObject:dict];
    }
   
}
- (void)returnB{
    [self dismissViewControllerAnimated:YES completion:^{
        
        
        
    }];
    
    [self.delegate sendArr:self.selectArray];
    
}
- (UITableView *)selectTv{
    if (!_selectTv) {
        _selectTv = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
        _selectTv.delegate = self;
        _selectTv.dataSource = self;
        _selectTv.separatorStyle = NO;
        _selectTv.tableFooterView = [[UIView alloc]init];
        [self.view addSubview:self.selectTv];
    }
    return _selectTv;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.selectArray.count;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dict = [self.selectArray objectAtIndex:indexPath.row];
    TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"select"];
    cell.leftLb.text = dict[@"title1"];
    cell.rightLb.text = dict[@"title2"];
    return cell;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    WSJPickerView *picker = [[WSJPickerView alloc]initWithFrame:self.view.bounds];
    selectIndex = indexPath.row;
    picker.delegate = self;
    if (indexPath.row == 0) {
        picker.arrayType = GenderArray;
    }if (indexPath.row == 1) {
        picker.arrayType = HeightArray;
    }if (indexPath.row == 2) {
        picker.arrayType = weightArray;
    }if (indexPath.row == 3) {
        picker.arrayType = DeteArray;
    }if (indexPath.row == 4) {
        picker.arrayType = hobbyArray;
        
    }
    [self.view addSubview:picker];
    
    
}
- (void)PickerSelectorIndixString:(NSString *)str{
    NSDictionary *dict = [self.selectArray objectAtIndex:selectIndex];
    NSMutableDictionary *muDict = [NSMutableDictionary dictionaryWithDictionary:dict];
    [muDict setObject:str forKey:@"title2"];
    [self.selectArray replaceObjectAtIndex:selectIndex withObject:muDict];
    [self.selectTv reloadData];
   
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
